package {
	import classes.Pagination;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import flashx.textLayout.formats.TextAlign;
	
	[SWF(frameRate="60", width="700", height="500")]
	
	public class test1 extends Sprite {
		private var sprites:Array = [];
		private var textFormat:TextFormat;
		
		public function test1() {
			textFormat = new TextFormat();
			textFormat.size = 24;
			textFormat.color = 0x000000;
			textFormat.underline = false;
			textFormat.align = TextAlign.CENTER;
			
			for(var i:uint = 0; i < 100; i++) {
				var sprite:Sprite = new Sprite();
				sprite.y = 50;
				sprite.graphics.clear();
				sprite.graphics.beginFill(Math.random() * 0xFFFFFF);
				sprite.graphics.drawRect(0, 0, 400, 400);
				sprite.graphics.endFill();
				
				var textField:TextField = sprite.addChild(new TextField()) as TextField;
				textField.text = "slide" + (i + 1);
				textField.autoSize = TextFieldAutoSize.CENTER;
				textField.defaultTextFormat = textFormat;
				textField.setTextFormat(textFormat);
				textField.x = (sprite.width - textField.width) / 2;
				textField.y = (sprite.height - textField.height) / 2;
				
				sprites.push(sprite);
			}
			 
			// ---
			
			var pg:Pagination = new Pagination(this, 10, 10, 100, 10, selectCallback, true);
			pg.height = 30;
			pg.showPage(20);
		}
		
		// --- PRIVATE
		
		private function selectCallback(page:uint):void {
			for each(var sprite:Sprite in sprites) {
				if(sprite.parent != null) {
					sprite.parent.removeChild(sprite);
				}
			}
			
			if(sprites.length) {
				addChild(sprites[page] as Sprite);
			}
		}
	}
}